#pragma once

#include "stb.h"

static const int max_order = 3;

struct sh_data
{
    float coeffs_r[max_order*max_order];
    float coeffs_g[max_order*max_order];
    float coeffs_b[max_order*max_order];
};

struct sh_node
{
    bool       is_leaf()   const { return ((child_start_type & leaf_type_mask) != 0); }
    stb_uint16 get_child() const { return child_start_type; }
    void       set_child(stb_uint16 idx) { child_start_type = idx & ~leaf_type_mask; }

private:
    static const stb_uint16 leaf_type_mask = 0x8000;
    stb_uint16 child_start_type; // The MSB indicates if it's a leaf. In this case, the 15 LSB gives the index to the data. 
    // Otherwise, it's an intermediates node, and it just gives the index to the 8 children

};

class sh_octree
{
public:
    sh_octree(int max_nodes_allowed = 16384);
    ~sh_octree();

    bool subdivide(stb_uint16 node);
    void set_data (stb_uint16 node);
    void clear();

    sh_node*    m_nodes;
private:
    stb_uint32  m_cur_nodes;
};
